package br.com.sankhya.copa;

import net.sf.jml.MsnMessenger;
import net.sf.jml.MsnUserStatus;
import net.sf.jml.event.MsnAdapter;
import net.sf.jml.impl.MsnMessengerFactory;

public class BasicMessenger {

    private String email;
    private String password;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    protected void initMessenger(MsnMessenger messenger) {
    	messenger.getOwner().setInitStatus(MsnUserStatus.ONLINE);
    	messenger.addListener(new MsnAdapter() {
    		@Override
    		public void exceptionCaught(MsnMessenger arg0, Throwable arg1) {
    			// TODO Auto-generated method stub
    			super.exceptionCaught(arg0, arg1);
    			
    			arg1.printStackTrace();
    		}
    	});
    }

    public void start() {
    	System.setProperty("msn.conn.timeout", "120");
    	
        //create MsnMessenger instance
        MsnMessenger messenger = MsnMessengerFactory.createMsnMessenger(email,
                password);

        //MsnMessenger support all protocols by default
        //messenger.setSupportedProtocol(new MsnProtocol[] { MsnProtocol.MSNP8 });

        //default init status is online, 
        //messenger.getOwner().setInitStatus(MsnUserStatus.BUSY);

        //log incoming message
        messenger.setLogIncoming(true);

        //log outgoing message
        messenger.setLogOutgoing(true);

        initMessenger(messenger);
        messenger.login();
    }

    public static void main(String[] args) throws Exception {
       /* if (args.length != 3) {
            System.out.println("Usage: java messengerClassName email password");
            return;
        }*/
        BasicMessenger messenger = new BasicMessenger();
        messenger.setEmail("code@sankhya.com.br");
        messenger.setPassword("100senha");
        messenger.start();
    }
}